home *** CD-ROM | disk | FTP | other *** search
/ Internet 53 / INTERNET53.iso / pc / software / windows / building / coldfusion studio evaluation / data1.cab / CFS_Wizards / CFML / Ldap_LdapAction.wml < prev    next >
Encoding:
Text File  |  1998-10-08  |  5.8 KB  |  241 lines

  1. <!---            NAVIGATION BUTTONS (view page)            --->
  2.  
  3. <CFIF ParameterExists( Form.btnView_Next )
  4.     or ParameterExists( Form.btnView_Previous )
  5.     or ParameterExists( Form.btnView_First )
  6.     or ParameterExists( Form.btnView_Last )
  7.     >
  8.  
  9.     <!--- retrieve DNs for all viewed records --->
  10.     <CFLDAP NAME="GetDNs"
  11.             SERVER="$${ServerName}"
  12.             PORT="$${ServerPort}"
  13.             USERNAME="$${Username}"
  14.             PASSWORD="$${Password}"
  15.             ACTION="query"
  16.             START="$${Root}"
  17.             SCOPE="oneLevel"
  18.             ATTRIBUTES="dn"
  19.             TIMEOUT="$${Timeout}"
  20.     >
  21.  
  22.  
  23.     <!--- default values --->
  24.     <CFSET New_dn = Form.dn>
  25.     <CFSET RecordFound = "no">
  26.  
  27.     <!--- scroll thru all entries and find the one we are looking for --->
  28.     <CFOUTPUT query="GetDNs">
  29.     <CFIF not RecordFound>
  30.         
  31.         <CFSET Current_dn = GetDNs.dn>
  32.  
  33.         <!--- what navigation button was used? --->
  34.  
  35.         <CFIF ParameterExists( Form.btnView_First ) 
  36.             and CurrentRow is 1
  37.             >
  38.             <CFSET New_dn = Current_dn>
  39.             <CFSET RecordFound = "yes">
  40.  
  41.         <CFELSEIF ParameterExists( Form.btnView_Last )
  42.             and CurrentRow is RecordCount
  43.             >
  44.             <CFSET New_dn = Current_dn>
  45.             <CFSET RecordFound = "yes">
  46.  
  47.         <CFELSEIF ParameterExists( Form.btnView_Previous )>
  48.             <CFIF Current_dn is Form.dn>
  49.                 <CFSET RecordFound = "yes">
  50.             <CFELSE>
  51.                 <CFSET New_dn = Current_dn>
  52.             </CFIF>
  53.  
  54.         <CFELSEIF ParameterExists( Form.btnView_Next )>
  55.             <CFIF New_dn is Form.dn
  56.                 and CurrentRow is not 1
  57.                 >
  58.                 <CFSET RecordFound = "yes">
  59.             </CFIF>
  60.             <CFSET New_dn = Current_dn>
  61.  
  62.         </CFIF>
  63.  
  64.     </CFIF>
  65.     </CFOUTPUT>
  66.  
  67.     <!--- return the view page displaying the required entry (first, previous, next or last) --->
  68.     <CFLOCATION url="$${SafeApplicationName}_LdapView.cfm?dn=#URLEncodedFormat(New_dn)#">
  69.  
  70.  
  71.  
  72. <!---            EDIT BUTTON (view page)            --->
  73.  
  74. <CFELSEIF ParameterExists( btnView_Edit )>
  75.  
  76.     <!--- redirect to edit page with passing the DN attribute --->
  77.     <CFLOCATION url="$${SafeApplicationName}_LdapEdit.cfm?dn=#URLEncodedFormat(Form.dn)#">
  78.  
  79.  
  80.  
  81.  
  82. <!---            ADD BUTTON (view page)            --->
  83.  
  84. <CFELSEIF ParameterExists( btnView_Add )>
  85.  
  86.     <!--- redirect to edit page without passing the DN attribute --->
  87.     <CFLOCATION url="$${SafeApplicationName}_LdapEdit.cfm">
  88.  
  89.  
  90.  
  91. <!---            DELETE BUTTON (view page)        --->
  92.  
  93. <CFELSEIF ParameterExists( btnView_Delete )>
  94.  
  95.     <!--- delete the selected entry --->
  96.     <CFLDAP SERVER="$${ServerName}"
  97.             PORT="$${ServerPort}"
  98.             USERNAME="$${Username}"
  99.             PASSWORD="$${Password}"
  100.             ACTION="delete"
  101.             DN="#Form.dn#"
  102.             TIMEOUT="$${Timeout}"
  103.     >
  104.     
  105.     <!--- redirect to view page without passing the DN attribute --->
  106.     <CFLOCATION url="$${SafeApplicationName}_LdapView.cfm">
  107.  
  108.  
  109.  
  110. <!---            CANCEL BUTTON (edit page)        --->
  111.  
  112. <CFELSEIF ParameterExists( btnEdit_Cancel )>
  113.  
  114.     <CFIF ParameterExists(Form.dn)>
  115.         <!--- if entry has been edited, return to the view page and display it --->
  116.         <CFLOCATION url="$${SafeApplicationName}_LdapView.cfm?dn=#URLEncodedFormat(Form.dn)#">
  117.     <CFELSE>
  118.         <!--- else just return to the view page --->
  119.         <CFLOCATION url="$${SafeApplicationName}_LdapView.cfm">
  120.     </CFIF>
  121.  
  122.  
  123.  
  124. <!---            OK BUTTON (edit page)            --->
  125.  
  126. <CFELSEIF ParameterExists( btnEdit_OK )>
  127.  
  128.     
  129.     <!--- default action --->
  130.     <CFSET Action = "ADD">
  131.  
  132.     <!--- is this a new entry? --->
  133.     <CFIF not ParameterExists(Form.dn)>
  134.     
  135.         <CFSET EntryDN = "$${FirstInDN}=#Form.$${FirstInDN}#, $${Root}">
  136.         
  137.         <!--- check whether the record with such dn already exists --->
  138.         <CFLDAP NAME="GetDNs"
  139.                 SERVER="$${ServerName}"
  140.                 PORT="$${ServerPort}"
  141.                 USERNAME="$${Username}"
  142.                 PASSWORD="$${Password}"
  143.                 ACTION="query"
  144.                 START="$${Root}"
  145.                 SCOPE="oneLevel"
  146.                 ATTRIBUTES="dn"
  147.                 TIMEOUT="20"
  148.         >
  149.  
  150.         <!--- check whether such record already exists --->
  151.         <CFLOOP query="GetDNs">
  152.             <CFIF GetDNs.dn is EntryDN>
  153.  
  154.                 <CFSET Action = "MODIFY">
  155.                 <CFBREAK>
  156.             
  157.             </CFIF>
  158.         </CFLOOP>
  159.  
  160.     <!--- ... else the entry already exists --->
  161.     <CFELSE>
  162.  
  163.         <CFSET EntryDN = #Form.dn#>
  164.         <CFSET Action = "MODIFY">
  165.  
  166.     </CFIF>
  167.  
  168.  
  169.     <!--- if entry already exists retrieve all its attributes --->
  170.     <CFIF Action is "MODIFY">
  171.         <CFLDAP NAME="CheckRecord"
  172.                 SERVER="205.181.21.78"
  173.                 PORT="389"
  174.                 USERNAME=""
  175.                 PASSWORD=""
  176.                 ACTION="query"
  177.                 START="#EntryDN#"
  178.                 SCOPE="base"
  179.                 ATTRIBUTES="#Form.Attributes#"
  180.                 TIMEOUT="20"
  181.                 MAXROWS="1"
  182.         >
  183.     </CFIF>
  184.  
  185.  
  186.     <!--- generate the attribute list for the ADD/MODIFY operation --->
  187.     <CFSET AttrValueList = ''>
  188.     <CFLOOP index="AttrName" list="#Form.Attributes#">
  189.  
  190.         <CFSET AttrValue = Evaluate('Form.#AttrName#')>
  191.         <CFSET AttrValue = Replace( AttrValue, ";", ";;", "ALL" )>
  192.         <CFSET AddToList = "no">
  193.  
  194.         <!--- if adding entry, use only non-empty attributes --->        
  195.         <CFIF Action is "ADD" 
  196.             and Trim(AttrValue) is not ''
  197.             >
  198.             <CFSET AddToList = "yes">
  199.  
  200.         <!--- ... else if modifying entry, use only attributes are being changed --->
  201.         <CFELSEIF Action is "MODIFY">
  202.             <CFIF Trim(AttrValue) is not Trim(Evaluate('CheckRecord.#AttrName#'))>
  203.                 <CFSET AddToList = "yes">
  204.             </CFIF>
  205.  
  206.         </CFIF>
  207.  
  208.         <!--- add to list of attributes and their values --->
  209.         <CFIF AddToList>
  210.             <CFSET AttrValueList = ListAppend( AttrValueList, AttrName & '=' & AttrValue & ',', ';' )>
  211.         </CFIF>
  212.  
  213.     </CFLOOP>
  214.  
  215.     <!--- add the objectClass attribute --->
  216.     <CFIF Action is 'ADD'>
  217.         <CFSET AttrValueList = ListAppend( AttrValueList, 'objectClass=$${ObjectClass}', ';' )>
  218.     </CFIF>
  219.     
  220.  
  221.     <!--- add/modify the entry --->
  222.     <CFIF #AttrValueList# is not ''>
  223.         <CFLDAP SERVER="$${ServerName}"
  224.                 PORT="$${ServerPort}"
  225.                 USERNAME="$${Username}"
  226.                 PASSWORD="$${Password}"
  227.                 ACTION="#Action#"
  228.                 DN="#EntryDN#"
  229.                 ATTRIBUTES="#AttrValueList#"
  230.                 TIMEOUT="20"
  231.         >
  232.     </CFIF>
  233.  
  234.     <!--- view added/modified entry --->
  235.     <CFLOCATION url="$${SafeApplicationName}_LdapView.cfm?dn=#URLEncodedFormat(EntryDN)#">
  236.  
  237. </CFIF>
  238.  
  239.  
  240.  
  241.